<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-md-6">
        <h2>商品修改</h2>

        <ol class="breadcrumb">
            <li>
                <a href="{:U('admin/Product/index')}">商品管理</a>
            </li>
            <li class="active">
                <strong>商品修改</strong>
            </li>
        </ol>
    </div>
    <div class="col-md-6">
    </div>
</div>
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>商品修改</h5>
        </div>
        <div class="ibox-content">
            <form method="post" action="{:U('admin/Product/do_edit')}" class="form-horizontal" enctype="multipart/form-data">
                <input name='id' type="hidden" value="{$product['id']}" />
                <div class="form-group"><label class="col-sm-2 control-label">商品名称：</label>
                    <div class="col-sm-8"><input name="title" type="text" class="form-control" value="{$product['title']}"></div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">分类：</label>
                    <div class="col-sm-2">
                        <select name="catalog_id" id="level1" class="form-control">
                            <volist name="level1_data" id="l1">
                            <option <if condition="$l1['id'] eq $level1"> selected="selected" </if> value="{$l1.id}" >{$l1.name}</option>
                            </volist>
                        </select>
                    </div>
                    <div class="col-sm-2">
                    <input type="hidden" id="level2_select" value="{$level2}" >
                        <select name="catalog_id" id="level2" class="form-control">
                            <option>请输入一级分类</option>
                        </select>
                    </div>
                     <div class="col-sm-2">
                     <input type="hidden" id="level3_select" value="{$level3}" >
                        <select name="catalog_id" id="level3" class="form-control">
                            <option>请输入二级分类</option>
                        </select>
                    </div>
                    
                </div>
                 <div class="form-group">
                    <label class="col-sm-2 control-label">价格：</label>
                    <div class="col-sm-3"><input name="price" type="text" class="form-control" value="{$product['price']}"></div>
                    <label class="col-sm-2 control-label">库存：</label>
                    <div class="col-sm-3"><input name="stock" type="text" class="form-control" value="{$product['stock']}"></div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group"><label class="col-sm-2 control-label">描述：</label>
                    <div class="col-sm-8">
                        <textarea name="desc" class="form-control" rows="8">{$product['desc']}</textarea>
                    </div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group"><label class="col-sm-2 control-label">内容：</label>
                    <div class="col-sm-8">
                        <textarea name="content" id="content" class="form-control">{$product['content']}</textarea>
                    </div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group"><label class="col-sm-2 control-label">图片：</label>
                <div class="col-sm-4">
                    <input type="text" id="img" name="img" class="form-control" value="{$product['img']}"  />
                </div>
                <div class="col-sm-2">
                    <a id="upload" href="#" class="btn btn-info btn-sm">上传文件</a>
                </div>
                <div class="col-sm-2" id="preview"></div>
                </div>
                <div class="form-group"><label class="col-sm-2 control-label"></label>
                    <div class="col-sm-8">
                        <p style="text-align:right"><button type="submit" class="btn btn-success">提交</button></p>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script src="__PUBLIC__/admin/js/plugins/kindeditor/kindeditor-all.js"></script>
<script src="__PUBLIC__/admin/js/plugins/kindeditor/lang/zh-CN.js"></script>
<script type="text/javascript" src="__PUBLIC__/admin/js/jquery.upload.js"></script>
<script>
    var editor;
    KindEditor.ready(function(K) {
        editor = K.create("#content",{
           uploadJson:"{:U('admin/Util/uploadJson')}",
           allowFlashUpload:false,
           allowMediaUpload:false,
           allowFileUpload:false,
           formatUploadUrl:false
        });
    }); 
    $("#upload").click(function(){
        $.upload({
            url: '{:U("admin/Util/upload")}', 
            fileName: 'file', 
            dataType: 'text',
            onSend: function() {
                    return true;
            },
            onComplate: function(data){
                if(data.indexOf('upload')>=0){
                    $("#img").val(data);
                    $("#preview").html('<img style="height:80px;" src="__ROOT__/'+data+'" />');    
                }else{
                    alert(data);
                }
            }
        });
        return false;
    });
    //下拉框的三级联动
    function level1change(){
        var id = $('#level1').val();
        var str="";
        $.get("{:U('admin/Product/getCatalog')}",{id:id},function(data){
            var level2_select=$('#level2_select').val();
            for(var i=0;i<data.length;i++){
                isSelected = level2_select == data[i].id?'selected="selected"':"";      //下拉框的默认选中
                str+='<option '+isSelected+' value="'+data[i].id+'">'+data[i].name+'</option>';
            }
            $('#level2').html(str);
            level2change();
        })
    }
    function level2change(){
        var id = $('#level2').val();
        var str="";
        $.get("{:U('admin/Product/getCatalog')}",{id:id},function(data){
            var level3_select=$('#level3_select').val();
            for(var i=0;i<data.length;i++){
                isSelected = level3_select == data[i].id?'selected="selected"':"";
                str+='<option '+isSelected+' value="'+data[i].id+'">'+data[i].name+'</option>';
            }
            $('#level3').html(str);
        })
    }
    $('#level1').change(level1change);
    $('#level2').change(level2change)
    level1change();
</script>


        